package com.wb.web.controller.learning;

import com.wb.common.core.controller.BaseController;
import com.wb.common.core.domain.AjaxResult;
import com.wb.common.core.page.TableDataInfo;
import com.wb.common.vo.LearningModelVO;
import com.wb.common.vo.MaterialsModelVO;
import com.wb.system.domain.ExamsEntity;
import com.wb.system.domain.LearningsEntity;
import com.wb.system.domain.MaterialsEntity;
import com.wb.system.service.LearningService;
import com.wb.system.service.MaterialsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 学习学习进度
 */
@RestController
@RequestMapping("learning")
@Api(tags = "学习进度")
public class LearningController extends BaseController {
    @Autowired
    private LearningService learningService;


    @PostMapping("/progress")
    @ApiOperation("获取学习进度")
    public AjaxResult progress(@Valid @RequestBody LearningModelVO learningModelVO) {
        List<LearningsEntity> list = learningService.progress(learningModelVO);
        return AjaxResult.success(list);
    }


    @GetMapping("/{id}")
    @ApiOperation("获取学习进度详情")
    public AjaxResult get(@PathVariable("id") Long id) {
        return AjaxResult.success(learningService.selectById(id));
    }

    @PostMapping("/add")
    @ApiOperation("学习进度创建")
    public AjaxResult add(@Valid @RequestBody LearningsEntity learningsEntity) {
        LearningsEntity learnings = new LearningsEntity();
        BeanUtils.copyProperties(learningsEntity, learnings);
        learningService.saveLearnings(learnings);
        return AjaxResult.success();
    }

    @PostMapping("/update")
    @ApiOperation("更新职位")
    public AjaxResult update(@RequestBody LearningsEntity learningsEntity) {
        LearningsEntity learnings = new LearningsEntity();
        BeanUtils.copyProperties(learningsEntity, learnings);
        learnings.setUpdateBy(getUsername());
        learningService.updateLearningsById(learnings);
        return AjaxResult.success();
    }

    @DeleteMapping("/deleteAll")
    @ApiOperation("删除All")
    public AjaxResult deleteAll(@RequestParam("ids") List<Long> ids) {
        learningService.removeLearningsByIds(ids);
        return AjaxResult.success();
    }
}
